package freespiritsocial.io.user.ui.fragment.mine

import android.content.Intent
import android.os.Bundle
import freespiritsocial.io.user.R
import freespiritsocial.io.user.base.BaseFragment
import freespiritsocial.io.user.databinding.FrgQrBinding
import freespiritsocial.io.user.util.CacheUtil
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.nav

class QRFrg: BaseFragment<BaseViewModel,FrgQrBinding>() {
    override fun layoutId(): Int = R.layout.frg_qr
    private val shareText by lazy(LazyThreadSafetyMode.NONE) {
        "${CacheUtil.getUser()?.userName} invites you to join Freespirit App. Click here to download the app: https://admin.freespiritsocial.io/#/freespirit?id=1467769907534340097 "
    }

    override fun initView(savedInstanceState: Bundle?) {
        mDatabind.ivBack.setOnClickListener {
            nav().navigateUp()
        }
        mDatabind.ivShare.setOnClickListener {
            share()
        }
    }

    private fun share() {
        Intent(Intent.ACTION_SEND).apply {
            type = "text/plain"
            putExtra(Intent.EXTRA_TEXT,shareText)
            startActivity(Intent.createChooser(this,"Share To..."))
        }
    }

}